<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<style>
#myView {
	width: 100%;
	min-height: 200px;
}

#myView2 {
	width: 100%;
	min-height: 200px;
}

#treeDiv {
	height: 100%;
	overflow-x:hidden; 
}

#content {
	height: 100%;
	overflow-x:hidden;
	overflow-y:auto;
}
</style>
<SCRIPT type="text/javascript">
	var nodes = new Array();
	var setting = {
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeClick : beforeClick,
			onClick : onClick
		},
	};

	var nodes = ztree_returnjson();
	function ztree_returnjson() {
		menuAjax();
		return nodes;
	}

	//Ajax获取数据
	function menuAjax() {
		var total = $.CurrentNavtab.find("#total").text();
		$.ajax({
			type : "POST",
			url : "admin/getmenus.shtml",
			async : false,
			dataType : "json",
			success : function(json) {
				nodes = [];
				if (json[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
					var menuList = eval(json.data);
					if (menuList.url == undefined) {
						menuList.url = "#";
					}
					for (var i = 0; i < menuList.length; i++) {
						var id = parseInt(menuList[i].id);
						var pId = parseInt(menuList[i].parentId);
						var name = menuList[i].name;
						var url = menuList[i].url;
						var lv = menuList[i].level;

						var node = {//todo 明天继续
							"id" : id,
							"pId" : pId,
							"name" : name,
							"lv" : lv
						};
						nodes.push(node);
					}
				} else {
					$.CurrentNavtab.find(this).alertmsg("初始化失败");
				}
			},
			error : function(json) {
				if (json.statusCode == 300 && json.message == "系统错误，操作失败！") {
					$.CurrentNavtab.find(this).alertmsg("系统错误，操作失败");
				}
			}
		});
	};

	function beforeClick(treeId, treeNode, clickFlag) {
		return true;
	}
	function onClick(event, treeId, treeNode, clickFlag) {
		$(this).bjuiajax('doLoad', {
			target : $.CurrentNavtab.find("#myView"),
			url : "menuManager/edit.shtml?no=" + treeNode.id
		});
		if (treeNode.lv == 6) {
			$.CurrentNavtab.find("#myView2").hide();
		} else {
			$.CurrentNavtab.find("#myView2").show();
			$(this).bjuiajax('doLoad', {
				target : $.CurrentNavtab.find("#myView2"),
				url : "menuManager/addMenuPage.shtml?no=" + treeNode.id
			});
		}
		;
	}

	$(function() {		
		$.fn.zTree.init($.CurrentNavtab.find("#treeDemo"), setting, nodes);
	});
</SCRIPT>
<div class="bjui-pageContent">
	<span id="total" name="total" hidden>${requestScope.total }</span>
	<div class="row" style="margin:0px;height:100%;">
		<div class="col-md-3" style="height:100%;">
				<div id="treeDiv">
				<ul id="treeDemo" class="ztree"></ul>
				</div>
		</div>
		<div class="col-md-9" style="height:100%;">
			<div id="content">
				<div id="myView" name="myView" class="col-md-12">
					<!-- 内嵌页面1 -->
				</div>
				<div id="myView2" class="col-md-12">
					<!-- 内嵌页面2 -->
				</div>
			</div>
		</div>
	</div>
</div>